#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <crtdbg.h>
#include "array2d.h"
#include "object.h"
#include "new.h"


#define _CRTDBG_MAP_ALLOC


void main()
{
	Pointer arr;
	Pointer brr;
	Pointer p;
	Pointer obj;
	obj = new(Object, 3, 3, 3);
	arr = new(Array2d, 4, 4);
	brr = new(Array2d, 5, 5);
	//assert(*(int*)array2d_cell_access(arr, 3, 3)==0);
	p = array2d_cell_access(arr, 0, 3);
	memcpy(p, obj, sizeof(struct Object));
	p = array2d_cell_access(arr, 3, 1);
	memcpy(p, obj, sizeof(struct Object));
	p = array2d_cell_access(arr, 0, 3);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	p = array2d_cell_access(arr, 3, 1);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	array2d_resize(&arr, 5, 5);
	p = array2d_cell_access(arr, 0, 3);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	p = array2d_cell_access(arr, 3, 1);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	p = array2d_cell_access(arr, 4, 4);
	memcpy(p, obj, sizeof(struct Object));
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
 	assert(array2d_copy(brr, arr, 0, 0)==1);
	p = array2d_cell_access(brr, 0, 3);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	p = array2d_cell_access(brr, 3, 1);
	assert(((struct Object*)p)->r==((struct Object*)obj)->r);
	delete(obj);
	delete(arr);
	delete(brr);
	_CrtDumpMemoryLeaks();
}